//
//  WXPAuthCompleteView.m
//  MexicoLoan
//
//  Created by wxp on 2025/3/6.
//

#import "WXPAuthCompleteView.h"

@implementation WXPAuthCompleteView

#pragma mark - lazy
- (UIView *)viewBack{
    if (_viewBack == nil) {
        _viewBack = [UIView new];
        _viewBack.backgroundColor = COLOR_WHITE;
        _viewBack.width = SCREEN_WIDTH-2*LEFT_MARDIN;
        [GlobalMethod setRoundView:_viewBack color:[UIColor clearColor] numRound:16 width:0];
    }
    return _viewBack;
}
- (UILabel *)labelTitle{
    if (_labelTitle == nil) {
        _labelTitle = [UILabel new];
        _labelTitle.numberOfLines = 0;
        _labelTitle.lineSpace = 4;
        _labelTitle.textAlignment = NSTextAlignmentCenter;
        _labelTitle.textColor = COLOR_BLACK;
        _labelTitle.font = [UIFont boldSystemFontOfSize:18];
    }
    return _labelTitle;
}
- (UILabel *)labelContent{
    if (_labelContent == nil) {
        _labelContent = [UILabel new];
        _labelContent.numberOfLines = 0;
        _labelContent.lineSpace = 4;
        _labelContent.textAlignment = NSTextAlignmentCenter;
        _labelContent.textColor = COLOR_CONTENT;
        _labelContent.fontNum = 12;
    }
    return _labelContent;
}

- (UIButton *)btnConfirm{
    if (_btnConfirm == nil) {
        _btnConfirm = [UIButton buttonWithType:UIButtonTypeCustom];
        _btnConfirm.backgroundColor = COLOR_PRIMARY;
        [_btnConfirm setTitleColor:COLOR_BLACK forState:UIControlStateNormal];
        [_btnConfirm setTitle:@"OK" forState:UIControlStateNormal];
        _btnConfirm.titleLabel.font = [UIFont boldSystemFontOfSize:14];
        _btnConfirm.tag = 1;
        [_btnConfirm addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _btnConfirm;
}

#pragma mark - 初始化
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.widthHeight = XY(SCREEN_WIDTH, SCREEN_HEIGHT);
        self.backgroundColor = [UIColor colorWithHexString:@"#000000" alpha:0.4];
        [self addSubView];//添加子视图
    }
    return self;
}

//添加subview
- (void)addSubView{
    [self addSubview:self.viewBack];
    [self.viewBack addSubview:self.labelTitle];
    [self.viewBack addSubview:self.labelContent];
    [self.viewBack addSubview:self.btnConfirm];
    
    //初始化页面
    [self resetViewWithModel:nil];
}

#pragma mark - 点击事件
- (void)btnClick:(UIButton *)sender{
    switch (sender.tag) {
        case 1:
        {
            [self removeFromSuperview];
            [Global_Nav pushVCName:@"WXPProductPackageVC" animated:true];
        }
            break;
            
        default:
            break;
    }
}

#pragma mark - 刷新view
- (void)resetViewWithModel:(id)model{
    [self.labelTitle fitTitle:@"Felicitaciones por completar la\nautenticación" variable:self.viewBack.width-2*22];
    self.labelTitle.centerXTop = XY(self.viewBack.width/2, (50));
    
    NSString * rangeStr = @"90%";
    NSString * contentStr = [NSString stringWithFormat:@"Hemos obtenido la mejor selección de productos para usted, con una tasa de aprobación de hasta el %@. ¡Solicite ya!", rangeStr];
    // 设置第一个单词的颜色为红色
    NSRange firstWordRange = [contentStr rangeOfString: rangeStr];
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString: contentStr];
    [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"#FF8420"] range:firstWordRange];
    // 设置第二个单词的字体为粗体
    NSRange secondWordRange = [contentStr rangeOfString: rangeStr];
    UIFont *boldFont = [UIFont boldSystemFontOfSize:18];
    [attributedString addAttribute:NSFontAttributeName value:boldFont range:secondWordRange];
    // 将 attributedString 设置为 label 的 attributedText
    self.labelContent.width = self.viewBack.width-2*(22);
    self.labelContent.attributedText = attributedString;
    [self.labelContent sizeToFit];
    
    self.labelContent.centerXTop = XY(self.viewBack.width/2, self.labelTitle.bottom+(29));
    
    self.btnConfirm.widthHeight = XY(self.viewBack.width-30-30, BUTTON_HEIGHT);
    self.btnConfirm.centerXTop = XY(self.viewBack.width/2, self.labelContent.bottom+(40));
    [GlobalMethod setRoundView:self.btnConfirm color:[UIColor clearColor] numRound:BUTTON_HEIGHT/2 width:0];
    
    self.viewBack.height = self.btnConfirm.bottom + self.labelTitle.top;
    self.viewBack.centerXCenterY = XY(SCREEN_WIDTH/2, SCREEN_HEIGHT/2);
}


@end
